// pages/order_list/order_list.js
import Toast from '../../miniprogram_npm/@vant/weapp/toast/toast';
var util = require("../../utils/util");

Page({

  /**
   * 页面的初始数据
   */
  data: {

    // 工人状态 false-在忙 true-空闲
    rpm_state:true,

    // 订单状态
    "state": "",

    tId: "",
    tAddress: "",
    skill: "",
    description: "",
    catchtime: "",
    EId:"",

    // 底部tabbar start
    tabbar_active: 1,
    tabbar_list: [{
      "url": "../recive_order/recive_order",
      "text": "接单",
      "icon": "todo-list",
      "info": 12,
    }, {
      "url": "../order_list/order_list",
      "text": "订单",
      "icon": "column",
      // "info": 99,
    }, {
      "url": "../personal_info/personal_info",
      "text": "我的",
      "icon": "smile"
    }, {
      "url": "../contact/contact",
      "text": "关于",
      "icon": "phone-circle"
    }],
    // 底部tabbar end

  },

  done() {
    // console.log('lalallalalal');
    // 修改订单状态
    this.setData({
      state: 'done',
      
    })
    const that = this;
    wx.request({
        url: 'http://localhost:8088/appFinish',
        method:"GET",
      data:{
        EId: this.data.EId,
        TId:this.data.tId,
      },
      success(res){
        var data1 = res.data;
        console.log(data1);
        if("SUCCESS"==data1){
          Toast('恭喜你~订单完成啦');
          wx.request({
            url: 'http://localhost:8088/getATaskCanBeFinish',
            method:"GET",
            data:{
              EId:that.data.EId,
            },
            header: { 'content-type': 'application/x-www-form-urlencoded' },
            success(res){
              var data1 = res.data;
              if(data1==null)
        {
            that.setData({
              rpm_state:false,
            })
        }
        if(data1!=null){
            that.setData({
              rpm_state:true,
              tId:data1.tId,
              tAddress:data1.tAddress,
              skill:data1.skill,
              description:data1.description,
              catchtime:util.formatTime(data1.catchTime,"M月D日 h:m:s")
          })
        }
            }
          });
        }
      }
    })
   
  },

  tabbar_onChange: function (res) {
    //  this.setData({
    //    tabbar_active: res.detail
    //  });
    // console.log(this.data.tabbar_list[res.detail].url);
    wx.navigateTo({
      url: this.data.tabbar_list[res.detail].url+"?Id="+this.data.EId,
    });
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      EId:options.Id
    })
    console.log(this.data.EId);
    const that = this;
    console.log(options.Id);
    console.log(this.data.EId);
    wx.request({
      url: 'http://localhost:8088/getEmployeeTaskToSelect',
      method:"GET",
      data:{
        EId: this.data.EId,
      },
      header: { 'content-type': 'application/x-www-form-urlencoded' },
      success(res){
        console.log(res.data);
        var index = 0;
        var info = 'tabbar_list['+ index + '].info';
        that.setData({
            elements:res.data,
            [info]:res.data.length
        })
      }
    });
    wx.request({
      url: 'http://localhost:8088/getATaskCanBeFinish',
      method:"GET",
      data:{
        EId:this.data.EId,
      },
      header: { 'content-type': 'application/x-www-form-urlencoded' },
      success(res){
        var data1 = res.data;
        console.log(data1);
        if(data1==null)
        {
            that.setData({
              rpm_state:false,
            })
        }
        if(data1!=null){
            that.setData({
              rpm_state:true,
              tId:data1.tId,
              tAddress:data1.tAddress,
              skill:data1.skill,
              description:data1.description,
              catchtime:util.formatTime(data1.catchTime,"M月D日 h:m:s")
          })
        }
        
      }
    });

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})